# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from datum.CDTEditor import *
from datum.CDTBufferedGraphics import *

class CDTEditorWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)
        self.editor = CDTEditor()
        
        self.setFocusPolicy(Qt.ClickFocus)
        # enable the input method
        self.setAttribute(Qt.WA_InputMethodEnabled, True);
        
    def keyPressEvent(self, event):
        k = event.key()
        event.accept()
    
    def inputMethodEvent(self, event):
        event.accept()
    
    def inputMethodQuery(self, query):
        if query == Qt.ImMicroFocus:
            return QVariant(QRect(0, 0, 0, 0))
        else:
            return QWidget.inputMethodQuery(self, query)
    
    def paintEvent(self, event):
        pt = QPainter(self)
        bufg = CDTBufferedGraphics(pt)
        self.editor.paint(bufg, event.rect)